﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;


namespace FAP.DataAccess.BLL
{
    public class danhmuc
    {
        public int id { get; set; }
        public string tendanhmuc { get; set; }
        public int websiteid { get; set; }
        public string topicid { get; set; }
        public string linkdanhmuc { get; set; }
        public string linkpost { get; set; }
        public string tag { get; set; }
        public int parentid { get; set; }
        public bool ispost { get; set; }
        public int trangthai { get; set; }
        public bool isdeleted { get; set; }
        public string link { get; set; }
        //public website website { get { return website.websiteSelectRow(websiteid); } }

        #region danhmucSelectAll
        public static List<danhmuc> danhmucSelectAll()
        {
            IDataReader dr = FAP.DataAccess.DAL.danhmucSelectAll();
            List<danhmuc> danhmucList = new List<danhmuc>();
            while (dr.Read())
            {
                danhmuc mydanhmuc = new danhmuc
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    tendanhmuc = !dr.IsDBNull(dr.GetOrdinal("tendanhmuc")) ? (string)dr["tendanhmuc"] : null,
                    websiteid = !dr.IsDBNull(dr.GetOrdinal("websiteid")) ? (int)dr["websiteid"] : 0,
                    topicid = !dr.IsDBNull(dr.GetOrdinal("topicid")) ? (string)dr["topicid"] : null,
                    linkdanhmuc = !dr.IsDBNull(dr.GetOrdinal("linkdanhmuc")) ? (string)dr["linkdanhmuc"] : null,
                    linkpost = !dr.IsDBNull(dr.GetOrdinal("linkpost")) ? (string)dr["linkpost"] : null,
                    tag = !dr.IsDBNull(dr.GetOrdinal("tag")) ? (string)dr["tag"] : null,
                    parentid = !dr.IsDBNull(dr.GetOrdinal("parentid")) ? (int)dr["parentid"] : 0,
                    ispost = !dr.IsDBNull(dr.GetOrdinal("ispost")) ? (bool)dr["ispost"] : false,
                    trangthai = !dr.IsDBNull(dr.GetOrdinal("trangthai")) ? (int)dr["trangthai"] : 0,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : ""
                };
                danhmucList.Add(mydanhmuc);
            }
            dr.Close();
            dr.Dispose();
            return danhmucList;
        }
        #endregion

        #region danhmucSelectRow
        public static danhmuc danhmucSelectRow(int id)
        {
            IDataReader dr = FAP.DataAccess.DAL.danhmucSelectRow(id);
            danhmuc danhmuc = null;

            if (dr.Read())
            {
                danhmuc = new danhmuc
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    tendanhmuc = !dr.IsDBNull(dr.GetOrdinal("tendanhmuc")) ? (string)dr["tendanhmuc"] : null,
                    websiteid = !dr.IsDBNull(dr.GetOrdinal("websiteid")) ? (int)dr["websiteid"] : 0,
                    topicid = !dr.IsDBNull(dr.GetOrdinal("topicid")) ? (string)dr["topicid"] : null,
                    linkdanhmuc = !dr.IsDBNull(dr.GetOrdinal("linkdanhmuc")) ? (string)dr["linkdanhmuc"] : null,
                    linkpost = !dr.IsDBNull(dr.GetOrdinal("linkpost")) ? (string)dr["linkpost"] : null,
                    tag = !dr.IsDBNull(dr.GetOrdinal("tag")) ? (string)dr["tag"] : null,
                    parentid = !dr.IsDBNull(dr.GetOrdinal("parentid")) ? (int)dr["parentid"] : 0,
                    ispost = !dr.IsDBNull(dr.GetOrdinal("ispost")) ? (bool)dr["ispost"] : false,
                    trangthai = !dr.IsDBNull(dr.GetOrdinal("trangthai")) ? (int)dr["trangthai"] : 0,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : ""
                };
            }
            dr.Close();
            dr.Dispose();
            return danhmuc;
        }
        #endregion

        #region danhmucSelectRowByForeignKey_websiteid
        public static List<danhmuc> danhmucSelectRowByForeignKey_websiteid(int websiteid)
        {
            IDataReader dr = FAP.DataAccess.DAL.danhmucSelectRowByForeignKey_websiteid(websiteid);
            List<danhmuc> danhmucList = new List<danhmuc>();
            while (dr.Read())
            {
                danhmuc mydanhmuc = new danhmuc
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    tendanhmuc = !dr.IsDBNull(dr.GetOrdinal("tendanhmuc")) ? (string)dr["tendanhmuc"] : null,
                    websiteid = !dr.IsDBNull(dr.GetOrdinal("websiteid")) ? (int)dr["websiteid"] : 0,
                    topicid = !dr.IsDBNull(dr.GetOrdinal("topicid")) ? (string)dr["topicid"] : null,
                    linkdanhmuc = !dr.IsDBNull(dr.GetOrdinal("linkdanhmuc")) ? (string)dr["linkdanhmuc"] : null,
                    linkpost = !dr.IsDBNull(dr.GetOrdinal("linkpost")) ? (string)dr["linkpost"] : null,
                    tag = !dr.IsDBNull(dr.GetOrdinal("tag")) ? (string)dr["tag"] : null,
                    parentid = !dr.IsDBNull(dr.GetOrdinal("parentid")) ? (int)dr["parentid"] : 0,
                    ispost = !dr.IsDBNull(dr.GetOrdinal("ispost")) ? (bool)dr["ispost"] : false,
                    trangthai = !dr.IsDBNull(dr.GetOrdinal("trangthai")) ? (int)dr["trangthai"] : 0,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : ""
                };
                danhmucList.Add(mydanhmuc);
            }
            dr.Close();
            dr.Dispose();
            return danhmucList;
        }
        #endregion

        #region danhmucInsertRow
        public static void danhmucInsertRow(int id, string tendanhmuc, int websiteid, string topicid, string linkdanhmuc, string linkpost, string tag, int parentid, bool ispost, int trangthai, bool isdeleted)
        {
            FAP.DataAccess.DAL.danhmucInsertRow(id, tendanhmuc, websiteid, topicid, linkdanhmuc, linkpost, tag, parentid, ispost, trangthai, isdeleted);
        }
        #endregion

        #region danhmucUpdateRow
        public static void danhmucUpdateRow(int id, string tendanhmuc, int websiteid, string topicid, string linkdanhmuc, string linkpost, string tag, int parentid, bool ispost, int trangthai, bool isdeleted)
        {
            FAP.DataAccess.DAL.danhmucUpdateRow(id, tendanhmuc, websiteid, topicid, linkdanhmuc, linkpost, tag, parentid, ispost, trangthai, isdeleted);
        }
        #endregion

        #region danhmucDeleteRow
        public static void danhmucDeleteRow(int id)
        {
            FAP.DataAccess.DAL.danhmucDeleteRow(id);
        }
        #endregion
    }
}